package com.bit.IO;

import org.w3c.dom.ls.LSOutput;

import java.io.File;
import java.io.IOException;

public class IOTest1 {
    public static void main(String[] args) throws IOException{
        File file = new File("d:/test.txt");
        System.out.println("文件是否存在："+file.exists());
        System.out.println("是否是普通文件："+file.isFile());
        System.out.println("是否是文件目录："+file.isDirectory());
        file.delete();
        System.out.println("=========================");

        //目录操作
        File file1 = new File("d:/test");
        System.out.println(file1.exists());
        System.out.println(file1.isDirectory());
        System.out.println(file1.isFile());
        System.out.println(file.getParent());


        System.out.println("=============================");

        //listFiles操作
        File file2 = new File("d:/test");
        File[] files = file2.listFiles();
        for(File f:files){
            System.out.println(f);
        }

        listAllFiles(file2);
    }

    // 递归的罗列出一个目录中的所有文件.
    private static void listAllFiles(File f){
       if(f.isDirectory()){
           File[] files = f.listFiles();
           for(File f1:files){
               listAllFiles(f1);
           }
       }else{
           System.out.println(f);
       }

    }

}
